﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace PSL.Package.System
{
    internal class PSL_IO
    {
        /// <summary>
        /// Init IO-System
        /// </summary>
        /// <param name="Host">Instance of an PSLScriptEngine</param>
        internal static void Init(PSLRuntime Host)
        {
            // Copy file
            // Copy directory / with subdir
            // List Directory Content
            // read file
            // write file
            // get filename
            // get filextension
            // get filename without extension
            ///Host.AddMethod("writealltext", PSL_IO.PSL_WriteAllText);
            ///Host.AddMethod("renamefile", PSL_IO.PSL_RenameFile);
            ///Host.AddMethod("movefile", PSL_IO.PSL_MoveFile);

        }

        internal static dynamic PSL_WriteAllText(string FunctionName, PSLParameter Parameter)
        {
            if (Parameter.ContainsParameter(true, "path", "content"))
            {
                File.WriteAllText(Parameter["path"], Parameter["content"]);
            }

            return null;
        }

        internal static dynamic PSL_RenameFile(string FunctionName, PSLParameter Parameter)
        {

            if (Parameter.ContainsParameter(true, "path", "newname"))
            {
                File.Move(Parameter["path"], Path.GetDirectoryName(Parameter["path"]) + "\\" + Parameter["newname"]);
            }

            return true;
        }

        internal static dynamic PSL_MoveFile(string FunctionName, PSLParameter Parameter)
        {
            if (Parameter.ContainsParameter(true, "path", "newpath"))
            {
                File.Move(Parameter["path"], Parameter["newpath"]);
            }

            return true;
        }
    }
}
